package com.zaicheng.cloud;

import com.zaicheng.cloud.context.named.NamedContextFactory;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.lang.Nullable;

import java.util.Map;

/**
 @author zaicheng
 @version 1.0
 @date 2022-04-19
 @email zzc15847256473@163.com
 */

public class RemoteCallContext extends NamedContextFactory<RemoteCallClientSpecification> {

    public RemoteCallContext() {
        super("remoteCall", "remoteCall.client.name",RemoteCallClientsConfiguration.class);
    }

    /**
     * 只从子容器中查找bean,返回bean实例
     * @param name
     * @param type
     * @param <T>
     * @return
     */
    @Nullable
    public <T> T getInstanceWithoutAncestors(String name,Class<?> type){
        return (T) BeanFactoryUtils.beanOfType(getContext(name),type);
    }

    @Nullable
    public <T> Map<String,T> getInstancesWithoutAncestors(String name,Class<?> type){
        return (Map<String, T>) this.getContext(name).getBeansOfType(type);
    }
}
